import socket
import struct
import sys

class AhoPack():

    aho_struct =  struct.Struct("!BH")

    def __init__(self,data,op_code=0):
        self.op_code = op_code
        self.data =  data.encode()
        self.lenght = len(self.data) + 3


    def pack(self):

        return  self.aho_struct.pack(self.op_code,self.lenght) + self.data  


if len(sys.argv) < 3:
    print("Need Args")
    sys.exit(0)
address = (sys.argv[1],int(sys.argv[2]))

s = socket.socket()
try:
    s.bind(address)
except :
    print(f"[ERROR] When binding {address[0]}:{address[1]}")
    s.close()
    sys.exit()

s.listen()
while True:
    conn,addr = s.accept()
    print(conn.recv(1024))
    conn.close()
